package com.blockmeta.bbs.baselibrary.utils.gson;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;

import java.lang.reflect.Type;

/**
 * @author AirThor
 * @date 2019/6/14.
 */
public class GsonUtil {
    //Gson异常数据解析错误处理
    public static Gson buildGson() {
        Gson gson = new GsonBuilder()
                .registerTypeAdapter(Integer.class, new IntegerGsonDeserializer())
                .registerTypeAdapter(int.class, new IntegerGsonDeserializer())
                .registerTypeAdapter(Double.class, new DoubleGsonDeserializer())
                .registerTypeAdapter(double.class, new DoubleGsonDeserializer())
                .registerTypeAdapter(Long.class, new LongGsonDeserializer())
                .registerTypeAdapter(long.class, new LongGsonDeserializer())
                .create();
        return gson;
    }
}
